package com.monboo.display
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class ControlBar extends Sprite
	{
		
		private var albumPlayer:AlbumLite;
		private var ctrlBar:Sprite;
		
		private var prebtn:Sprite;
		private var nextbtn:Sprite;
		private var playbtn:MovieClip;
		private var effectbtn:MovieClip;
		private var fullscreenbtn:MovieClip;
		
		public function ControlBar(ctrlUI:Class,_albumPlayer:AlbumLite)
		{
			albumPlayer = _albumPlayer;
			ctrlBar = new ctrlUI();
			addChild(ctrlBar);
			
			prebtn = ctrlBar.getChildByName("prebtn") as Sprite;
			nextbtn = ctrlBar.getChildByName("nextbtn") as Sprite;
			prebtn.buttonMode = true;
			nextbtn.buttonMode = true;
			
			playbtn = ctrlBar.getChildByName("playbtn") as MovieClip;
			playbtn.buttonMode = true;
			
			if(albumPlayer.autoState){
				playbtn.gotoAndStop(2);
			}else{
				playbtn.gotoAndStop(1);
			}
			
			
			addControlEvent();
		}
		public function addControl(ctrlName:String):void{
			switch(ctrlName){
				case "effect":
					effectbtn = ctrlBar.getChildByName("effectbtn") as MovieClip;
					effectbtn.addEventListener(MouseEvent.CLICK,effectFun);
					break;
				case "fullScreen":
					fullscreenbtn = ctrlBar.getChildByName("fullScreenbtn") as MovieClip;
					fullscreenbtn.addEventListener(MouseEvent.CLICK,fullscreenFun);
					break;
			}
		}
		public function updateControl():void{
			if(albumPlayer.autoState){
				playbtn.gotoAndStop(2);
			}else{
				playbtn.gotoAndStop(1);
			}
		}
		
		private function effectFun(e:MouseEvent):void{
			if(effectbtn.currentFrame == 1){
				effectbtn.gotoAndStop(2);
				albumPlayer.openEffect(false);
			}else{
				effectbtn.gotoAndStop(1);
				albumPlayer.openEffect(true);
			}
			
		}
		private function fullscreenFun(e:MouseEvent):void{
			if(fullscreenbtn.currentFrame == 1){
				fullscreenbtn.gotoAndStop(2);
			}else{
				fullscreenbtn.gotoAndStop(1);
			}
			albumPlayer.fullScreen();
		}
		private function addControlEvent():void{
			prebtn.addEventListener(MouseEvent.CLICK,preFunction);
			nextbtn.addEventListener(MouseEvent.CLICK,nextFunction);
			playbtn.addEventListener(MouseEvent.CLICK,playFunction);
		}
		private function preFunction(e:MouseEvent):void{
			albumPlayer.pre();
		}
		private function nextFunction(e:MouseEvent):void{
			albumPlayer.next();
		}
		private function playFunction(e:MouseEvent):void{
			if(playbtn.currentFrame == 1){
				playbtn.gotoAndStop(2);
				albumPlayer.play();
			}else{
				playbtn.gotoAndStop(1);
				albumPlayer.stop();
			}
		}
	}
}